package com.jymj.service.impl;

import com.jymj.dao.SysRoleProjDao;
import com.jymj.service.SysRoleProjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dl on 2017/7/25.
 */
@Service("sysRoleProjService")
public class SysRoleProjServiceImpl implements SysRoleProjService {

    @Autowired
    private SysRoleProjDao sysRoleProjDao;

    @Override
    @Transactional
    public void saveOrUpdate(Long roleId, List<Long> projIdList) {
        if (projIdList == null || projIdList.isEmpty()) {
            return;
        }
        //先删除角色与项目关系
        sysRoleProjDao.delete(roleId);

        //保存角色与项目关系
        Map<String, Object> map = new HashMap<>();
        map.put("roleId", roleId);
        map.put("projIdList", projIdList);
        sysRoleProjDao.save(map);
    }

    @Override
    public List<Long> queryProjIdList(Long roleId) {
        return sysRoleProjDao.queryProjIdList(roleId);
    }

    @Override
    public List<Long> queryRoleList(Long userId) {
        return sysRoleProjDao.queryRoleList(userId);
    }

    @Override
    public void save(Long projId, List<Long> roleIdList) {
        Map<String, Object> map = new HashMap<>();
        map.put("projId", projId);
        map.put("roleIdList", roleIdList);
        sysRoleProjDao.saveProj(map);
    }
}
